/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * jifAdministracion.java
 *
 * Created on 04-ago-2010, 8:38:51
 */

package Licitaciones;

import administracion.delegate.GestionPedidosDelegate;
import administracion.helper.Listas;
import administracion.helper.MiTablePrint;
import administracion.helper.Utiles_MensajesDialogo;
import administracion.helper.Utiles_Tabla;
import com.jidesoft.hints.ListDataIntelliHints;
import java.awt.event.KeyEvent;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JFrame;
import org.jdesktop.beansbinding.AutoBinding;
import org.jdesktop.beansbinding.BindingGroup;
import org.jdesktop.beansbinding.ELProperty;
import org.jdesktop.swingbinding.JTableBinding;
import org.jdesktop.swingbinding.SwingBindings;
import suministros.ejb30.TO.EmpresaTO;
import suministros.ejb30.TO.LicitacionTO;
import suministros.ejb30.TO.ProveedorTO;
import suministros.ejb30.TO.TransferenciaTO;
import suministros.ejb30.entity.Proveedor;
import suministros.ejb30.helper.Utiles_Convertir;

/**
 *
 * @author Diana
 */
public class jifAdministracion extends javax.swing.JInternalFrame {
    private JTableBinding jTableBinding;
    private ListDataIntelliHints intelliHintsProveedor;
    private ListDataIntelliHints intelliHintsCodigos;
    private Proveedor proveedor;
    List<LicitacionTO> licitaciones;
    JFrame padre;
    List<EmpresaTO> empresas;

    /** Creates new form jifAdministracion */
    public jifAdministracion(JFrame padre) {

        this.licitaciones = new ArrayList(1);
        this.padre=padre;
        initComponents();
        empresas = Listas.getEmpresas();
        if(empresas.isEmpty()){
            this.jCheckBox1.setEnabled(false);
        }
        try {
            Listas.cargarAnosMeses();
            cargaHintsIndependientes();
            obtenerCodigos();
        } catch (Exception ex) {
            Logger.getLogger(jifAdministracion.class.getName()).log(Level.SEVERE, null, ex);
        }
        llenarComboAno();
        this.jCheckBox1.setSelected(false);
        this.llenarComboEmpresa();
        this.jckbActivas.setSelected(true);
        this.jcbEmpresa.setEnabled(false);

    }
     private void cargaHintsIndependientes() throws Exception {
    this.intelliHintsProveedor = new ListDataIntelliHints(this.jtfDescripcion, Listas.getProveedores());
     }
     public void obtenerCodigos() throws Exception{
           List<TransferenciaTO>  codigos= new ArrayList<TransferenciaTO> ();
           codigos= GestionPedidosDelegate.getInstance().obtenerCodigos(5);
           this.intelliHintsCodigos = new ListDataIntelliHints(this.jtfDescipcionLic, codigos);
    }
     private void llenarComboEmpresa() {
        empresas = null;
        List listaPaises_cbo = this.cboBeanBindingEmpresa1.getLista();
        listaPaises_cbo.clear();
        try
        {
          if(this.jCheckBox1.isSelected()){
                empresas = Listas.getEmpresas();
            }
            else{
                empresas = Listas.getEmpresaPrincipal();
            }
          this.cboBeanBindingEmpresa1.setLista(empresas);
          this.bindingGroup.bind();
          this.jcbEmpresa.updateUI();
          this.jcbEmpresa.setSelectedIndex(0);
        } catch (Exception ex) {
          Utiles_MensajesDialogo.mensajeAlerta("Error al obtener empresas\n" + ex.getMessage());
          ex.printStackTrace();
          Logger.getLogger(jifAdministracion.class.getName()).log(Level.SEVERE, null, ex);
        }
      }
      private void llenarComboAno()
  {
    List listaAnos = null;
    List listaAnos_cbo = this.cboBeanBindingAno1.getLista();
    listaAnos_cbo.clear();
    try
    {
      listaAnos = Listas.getAnos();
      this.cboBeanBindingAno1.setLista(listaAnos);
      this.bindingGroup.bind();
      this.jcbAno.updateUI();
      this.jcbAno.setSelectedIndex(-1);
    } catch (Exception ex) {
      Utiles_MensajesDialogo.mensajeAlerta("Error al obtener años\n" + ex.getMessage());
      ex.printStackTrace();
      Logger.getLogger(jifAdministracion.class.getName()).log(Level.SEVERE, null, ex);
    }
  }

     private void buscarRazonSocial()
      {
        ProveedorTO pro;
        if (this.jtfRuc.getText().trim().length() < 1) {
              try { pro = (ProveedorTO)this.intelliHintsProveedor.getSelectedHint();
              } catch (NullPointerException ex) {
                pro = null;
              }
            }
        else {
          pro = Listas.getProveedorcodigo(this.jtfRuc.getText().trim());
        }
        if (pro == null) {
          Utiles_MensajesDialogo.mensajeError("El proveedor no existe!");
          this.jtfRuc.setText("");
          pro = null;
        }
        else {
          this.proveedor = Utiles_Convertir.convertirToProveedor_ProveedorTO(pro);
          this.jtfDescripcion.setText(pro.getRazon() + " - " + pro.getCodProveedor());
          this.jtfRuc.setText(pro.getCodProveedor());
          this.consultar();
        }

      }
       private void buscarDescripcionLicitacion()
      {
        TransferenciaTO tra= new TransferenciaTO();
        if (this.jtfCodigo.getText().trim().length() < 1) {
              try { tra = (TransferenciaTO)this.intelliHintsCodigos.getSelectedHint();
              } catch (NullPointerException ex) {
                tra = null;
              }
            }

        if (tra == null) {
          Utiles_MensajesDialogo.mensajeError("La licitacion no existe!");
          this.jtfCodigo.setText("");
          tra = null;
        }
        else {
          this.jtfDescipcionLic.setText(tra.getCodigo() + " - " + tra.getZona());
          this.jtfCodigo.setText(tra.getZona());
          this.jtfRuc.setText("");
          this.jtfDescripcion.setText("");
          consultar();

        }
      }

    public void consultar(){
        boolean estado=true;
         try {
            
            if(this.jckbActivas.isSelected()){
                if(this.jtfCodigo.getText().compareTo("")!=0){
                this.licitaciones = GestionPedidosDelegate.getInstance().getDatosLicitacionCodigo(this.jtfCodigo.getText().trim(),true, empresas.get(this.jcbEmpresa.getSelectedIndex()).getCodigo());
  
                }
                else{
                    if(this.jtfDescripcion.getText().compareTo("")!=0){
                        if(this.jcbAno.getSelectedIndex()!=-1){
                            this.licitaciones = GestionPedidosDelegate.getInstance().getDatosLicitacionProveedorAno(this.jtfRuc.getText().trim(), this.jcbAno.getSelectedItem().toString(),true,empresas.get(this.jcbEmpresa.getSelectedIndex()).getCodigo());
                        }
                        else{
                              this.licitaciones = GestionPedidosDelegate.getInstance().getDatosLicitacionProveedor(this.jtfRuc.getText().trim(),true,empresas.get(this.jcbEmpresa.getSelectedIndex()).getCodigo());
                        }
                    }
                    else{
                        if(this.jcbAno.getSelectedIndex()!=-1){
                             this.licitaciones = GestionPedidosDelegate.getInstance().getDatosLicitacionAno(this.jcbAno.getSelectedItem().toString(),true,empresas.get(this.jcbEmpresa.getSelectedIndex()).getCodigo());
                        }
                        else
                        {
                             Utiles_MensajesDialogo.mensajeAlerta("No se ha seleccionado ninguna licitacion a buscar");
                             estado=false;
                        }

                    }
                }
            }
            else{
                if(this.jtfCodigo.getText().compareTo("")!=0){
                this.licitaciones = GestionPedidosDelegate.getInstance().getDatosLicitacionCodigo(this.jtfCodigo.getText().trim(),false,empresas.get(this.jcbEmpresa.getSelectedIndex()).getCodigo());
            }
            else{
                if(this.jtfDescripcion.getText().compareTo("")!=0){
                    if(this.jcbAno.getSelectedIndex()!=-1){
                        this.licitaciones = GestionPedidosDelegate.getInstance().getDatosLicitacionProveedorAno(this.jtfRuc.getText().trim(), this.jcbAno.getSelectedItem().toString(),false,empresas.get(this.jcbEmpresa.getSelectedIndex()).getCodigo());
                    }
                    else{
                          this.licitaciones = GestionPedidosDelegate.getInstance().getDatosLicitacionProveedor(this.jtfRuc.getText().trim(),false,empresas.get(this.jcbEmpresa.getSelectedIndex()).getCodigo());
                    }
                }
                else{
                    if(this.jcbAno.getSelectedIndex()!=-1){
                         this.licitaciones = GestionPedidosDelegate.getInstance().getDatosLicitacionAno(this.jcbAno.getSelectedItem().toString(),false,empresas.get(this.jcbEmpresa.getSelectedIndex()).getCodigo());
                    }
                    else
                    {
                         Utiles_MensajesDialogo.mensajeAlerta("No se ha seleccionado ninguna licitacion a buscar");
                         estado=false;
                    }

                }
            }
            }


        } catch (Exception ex) {
            Logger.getLogger(jifAdministracion.class.getName()).log(Level.SEVERE, null, ex);
        }
        if(estado){
           if(licitaciones.isEmpty()){
            Utiles_MensajesDialogo.mensajeAlerta("No se han encontrado licitaciones");
           }
         }
     actualizarTabla();

    }
    public void actualizarTabla(){

        this.bindingGroup = new BindingGroup();
        this.jTableBinding = SwingBindings.createJTableBinding(AutoBinding.UpdateStrategy.READ, this.licitaciones, this.jtDetalleSuministro);

        JTableBinding.ColumnBinding columnBinding0 = this.jTableBinding.addColumnBinding(ELProperty.create("${codProceso}"));

        columnBinding0.setColumnName("Cod Proceso");
        columnBinding0.setColumnClass(String.class);
        columnBinding0.setEditable(false);

        JTableBinding.ColumnBinding columnBinding1 = this.jTableBinding.addColumnBinding(ELProperty.create("${descripcion}"));

        columnBinding1.setColumnName("Descripcion");
        columnBinding1.setColumnClass(String.class);
        columnBinding1.setEditable(false);

        JTableBinding.ColumnBinding columnBinding2 = this.jTableBinding.addColumnBinding(ELProperty.create("${tipo}"));

        columnBinding2.setColumnName("Tipo");
        columnBinding2.setColumnClass(String.class);
        columnBinding2.setEditable(true);

        JTableBinding.ColumnBinding columnBinding3 = this.jTableBinding.addColumnBinding(ELProperty.create("${proveedor}"));

        columnBinding3.setColumnName("Proveedor");
        columnBinding3.setColumnClass(String.class);
        columnBinding3.setEditable(false);

        JTableBinding.ColumnBinding columnBinding4 = this.jTableBinding.addColumnBinding(ELProperty.create("${fechaIni}"));

        columnBinding4.setColumnName("FechaInicial");
        columnBinding4.setColumnClass(String.class);
        columnBinding4.setEditable(false);
         JTableBinding.ColumnBinding columnBinding5 = this.jTableBinding.addColumnBinding(ELProperty.create("${fechaFin}"));

        columnBinding5.setColumnName("FechaFinal");
        columnBinding5.setColumnClass(String.class);
        columnBinding5.setEditable(false);
         JTableBinding.ColumnBinding columnBinding6 = this.jTableBinding.addColumnBinding(ELProperty.create("${monto}"));

        columnBinding6.setColumnName("Monto");
        columnBinding6.setColumnClass(BigDecimal.class);
        columnBinding6.setEditable(false);

        this.bindingGroup.addBinding(this.jTableBinding);
        this.bindingGroup.bind();

        int[] porcentajes= {8,40,8,20,8,8,8};
        try {
            Utiles_Tabla.definirAnchoColumnasJTable(jtDetalleSuministro, porcentajes);
            // MiTablePrint.autoSizeTableColumns(this.jtDetalleSuministro);
        } catch (Exception ex) {
            Logger.getLogger(jdAdministrarLicitacion.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
    public   void cerrar(){
      int res = javax.swing.JOptionPane.showConfirmDialog( this,"Esta seguro de salir?",
      "Confirmar",javax.swing.JOptionPane.YES_NO_OPTION );
            if(res==javax.swing.JOptionPane.YES_OPTION){
                    this.dispose();

         }
      }
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {
        bindingGroup = new org.jdesktop.beansbinding.BindingGroup();

        cboBeanBindingAno1 = new administracion.BeanBinding.CboBeanBindingAno();
        cboBeanBindingEmpresa1 = new administracion.BeanBinding.CboBeanBindingEmpresa();
        jPanel1 = new javax.swing.JPanel();
        jScrollPane2 = new javax.swing.JScrollPane();
        jtDetalleSuministro = new javax.swing.JTable();
        this.jtDetalleSuministro.getTableHeader().setReorderingAllowed(false) ;
        jbtDetalles = new javax.swing.JButton();
        jbtEliminar = new javax.swing.JButton();
        jbBaja = new javax.swing.JButton();
        jLabel2 = new javax.swing.JLabel();
        jbtBuscar = new javax.swing.JButton();
        jLabel4 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jtfRuc = new javax.swing.JTextField();
        jcbAno = new javax.swing.JComboBox();
        jtfDescripcion = new javax.swing.JTextField();
        jLabel1 = new javax.swing.JLabel();
        jtfCodigo = new javax.swing.JTextField();
        jckbActivas = new javax.swing.JCheckBox();
        jcbEmpresa = new javax.swing.JComboBox();
        jlabelLicitacion = new javax.swing.JLabel();
        jtfDescipcionLic = new javax.swing.JTextField();
        jCheckBox1 = new javax.swing.JCheckBox();
        jbtCancelar = new javax.swing.JButton();
        jbtImprimir = new javax.swing.JButton();

        setIconifiable(true);
        setTitle("ADMINISTRAR LICITACIONES");

        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Busqueda Avanzada", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 0, 11), new java.awt.Color(0, 0, 255))); // NOI18N

        jtDetalleSuministro.setFont(new java.awt.Font("Arial", 0, 12));
        jtDetalleSuministro.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "CODIGO", "DESCRIPCION", "TIPO", "PROVEEDOR", "FECHA INICIO", "FECHA FIN", "MONTO"
            }
        ) {
            Class[] types = new Class [] {
                java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class
            };

            public Class getColumnClass(int columnIndex) {
                return types [columnIndex];
            }
        });
        jScrollPane2.setViewportView(jtDetalleSuministro);

        jbtDetalles.setFont(new java.awt.Font("Arial", 1, 12)); // NOI18N
        jbtDetalles.setIcon(new javax.swing.ImageIcon(getClass().getResource("/iconoscomb/16x16ozygen/actions/view_detailed.png"))); // NOI18N
        jbtDetalles.setText("DETALLES");
        jbtDetalles.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbtDetallesActionPerformed(evt);
            }
        });

        jbtEliminar.setFont(new java.awt.Font("Arial", 1, 12));
        jbtEliminar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/iconoscomb/16x16ozygen/actions/remove.png"))); // NOI18N
        jbtEliminar.setText("ELIMINAR");
        jbtEliminar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbtEliminarActionPerformed(evt);
            }
        });

        jbBaja.setFont(new java.awt.Font("Arial", 1, 12));
        jbBaja.setText("DAR DE BAJA");
        jbBaja.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbBajaActionPerformed(evt);
            }
        });

        jLabel2.setFont(new java.awt.Font("Arial", 1, 12));
        jLabel2.setText("PROVEEDOR:");

        jbtBuscar.setFont(new java.awt.Font("Arial", 1, 12));
        jbtBuscar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/iconoscomb/16x16ozygen/actions/find.png"))); // NOI18N
        jbtBuscar.setText("Buscar");
        jbtBuscar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbtBuscarActionPerformed(evt);
            }
        });
        jbtBuscar.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusGained(java.awt.event.FocusEvent evt) {
                jbtBuscarFocusGained(evt);
            }
        });
        jbtBuscar.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                jbtBuscarKeyPressed(evt);
            }
        });

        jLabel4.setFont(new java.awt.Font("Arial", 1, 12));
        jLabel4.setText("RUC:");

        jLabel3.setFont(new java.awt.Font("Arial", 1, 12));
        jLabel3.setText("AÑO:");

        jtfRuc.setFont(new java.awt.Font("Arial", 0, 12));
        jtfRuc.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jtfRucActionPerformed(evt);
            }
        });

        jcbAno.setFont(new java.awt.Font("Arial", 0, 12));

        org.jdesktop.beansbinding.ELProperty eLProperty = org.jdesktop.beansbinding.ELProperty.create("${lista}");
        org.jdesktop.swingbinding.JComboBoxBinding jComboBoxBinding = org.jdesktop.swingbinding.SwingBindings.createJComboBoxBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, cboBeanBindingAno1, eLProperty, jcbAno);
        bindingGroup.addBinding(jComboBoxBinding);

        jcbAno.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                jcbAnoKeyPressed(evt);
            }
        });

        jtfDescripcion.setFont(new java.awt.Font("Arial", 0, 12));
        jtfDescripcion.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jtfDescripcionActionPerformed(evt);
            }
        });
        jtfDescripcion.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                jtfDescripcionKeyPressed(evt);
            }
        });

        jLabel1.setFont(new java.awt.Font("Arial", 1, 12));
        jLabel1.setText("COD. LICITACION:");

        jtfCodigo.setFont(new java.awt.Font("Arial", 0, 12));
        jtfCodigo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jtfCodigoActionPerformed(evt);
            }
        });
        jtfCodigo.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                jtfCodigoKeyPressed(evt);
            }
        });

        jckbActivas.setFont(new java.awt.Font("Arial", 1, 12));
        jckbActivas.setText("LICITACIONES ACTIVAS");
        jckbActivas.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jckbActivasActionPerformed(evt);
            }
        });

        eLProperty = org.jdesktop.beansbinding.ELProperty.create("${lista}");
        jComboBoxBinding = org.jdesktop.swingbinding.SwingBindings.createJComboBoxBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, cboBeanBindingEmpresa1, eLProperty, jcbEmpresa);
        bindingGroup.addBinding(jComboBoxBinding);

        jcbEmpresa.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                jcbEmpresaKeyPressed(evt);
            }
        });

        jlabelLicitacion.setFont(new java.awt.Font("Arial", 1, 12));
        jlabelLicitacion.setText("DESCRIPCION:");

        jtfDescipcionLic.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jtfDescipcionLicActionPerformed(evt);
            }
        });
        jtfDescipcionLic.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                jtfDescipcionLicKeyPressed(evt);
            }
        });

        jCheckBox1.setFont(new java.awt.Font("Arial", 1, 12));
        jCheckBox1.setText("OTRAS EMPRESAS");
        jCheckBox1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jCheckBox1ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 694, Short.MAX_VALUE)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addComponent(jCheckBox1)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jcbEmpresa, javax.swing.GroupLayout.PREFERRED_SIZE, 179, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addComponent(jckbActivas)
                            .addComponent(jbtBuscar)
                            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel1Layout.createSequentialGroup()
                                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                        .addComponent(jLabel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                        .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                            .addComponent(jLabel3)
                                            .addComponent(jLabel4)))
                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                        .addComponent(jcbAno, javax.swing.GroupLayout.PREFERRED_SIZE, 78, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addGroup(jPanel1Layout.createSequentialGroup()
                                            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                                .addComponent(jtfRuc, javax.swing.GroupLayout.Alignment.LEADING)
                                                .addComponent(jtfCodigo, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.PREFERRED_SIZE, 143, javax.swing.GroupLayout.PREFERRED_SIZE))
                                            .addGap(18, 18, 18)
                                            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                                .addComponent(jlabelLicitacion)
                                                .addComponent(jLabel2))
                                            .addGap(18, 18, 18)
                                            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                                .addComponent(jtfDescripcion)
                                                .addComponent(jtfDescipcionLic, javax.swing.GroupLayout.PREFERRED_SIZE, 316, javax.swing.GroupLayout.PREFERRED_SIZE)))))
                                .addGroup(jPanel1Layout.createSequentialGroup()
                                    .addComponent(jbtDetalles)
                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                    .addComponent(jbtEliminar, javax.swing.GroupLayout.PREFERRED_SIZE, 109, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                    .addComponent(jbBaja))))
                        .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addComponent(jckbActivas)
                .addGap(4, 4, 4)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jCheckBox1)
                    .addComponent(jcbEmpresa, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel1)
                            .addComponent(jtfCodigo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel4)
                            .addComponent(jtfRuc, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jtfDescipcionLic, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jlabelLicitacion))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jtfDescripcion, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel2))))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel3)
                    .addComponent(jcbAno, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jbtBuscar)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 153, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jbtDetalles)
                    .addComponent(jbtEliminar)
                    .addComponent(jbBaja)))
        );

        jbtCancelar.setFont(new java.awt.Font("Arial", 1, 12));
        jbtCancelar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/iconoscomb/16x16ozygen/actions/button_cancel.png"))); // NOI18N
        jbtCancelar.setText("CERRAR");
        jbtCancelar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbtCancelarActionPerformed(evt);
            }
        });

        jbtImprimir.setFont(new java.awt.Font("Arial", 1, 12));
        jbtImprimir.setIcon(new javax.swing.ImageIcon(getClass().getResource("/iconoscomb/16x16ozygen/actions/document_print.png"))); // NOI18N
        jbtImprimir.setText("IMPRIMIR");
        jbtImprimir.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbtImprimirActionPerformed(evt);
            }
        });
        jbtImprimir.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                jbtImprimirKeyPressed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, 700, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap(262, Short.MAX_VALUE)
                .addComponent(jbtImprimir)
                .addGap(18, 18, 18)
                .addComponent(jbtCancelar)
                .addGap(236, 236, 236))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jbtImprimir)
                    .addComponent(jbtCancelar))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        bindingGroup.bind();

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jbtBuscarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbtBuscarActionPerformed
      this.consultar();
    }//GEN-LAST:event_jbtBuscarActionPerformed

    private void jtfCodigoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jtfCodigoActionPerformed

    }//GEN-LAST:event_jtfCodigoActionPerformed

    private void jtfDescripcionActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jtfDescripcionActionPerformed
      buscarRazonSocial();
    }//GEN-LAST:event_jtfDescripcionActionPerformed

    private void jtfDescripcionKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jtfDescripcionKeyPressed
        this.jcbAno.setSelectedIndex(-1);
        if (this.jtfRuc.getText().trim().length() > 0)
            this.jtfRuc.setText("");
    }//GEN-LAST:event_jtfDescripcionKeyPressed

    private void jtfRucActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jtfRucActionPerformed
         if (this.jtfRuc.getText().trim().length() < 1)
            this.jtfRuc.requestFocus();
        else
            buscarRazonSocial();
    }//GEN-LAST:event_jtfRucActionPerformed

    private void jbtCancelarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbtCancelarActionPerformed
       cerrar();
    }//GEN-LAST:event_jbtCancelarActionPerformed

    private void jbtDetallesActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbtDetallesActionPerformed
        String codigo=null;
        String descripcion=null;
        String prove= null;
        String fechaIni=null;
        String fechaFin=null;
        String monto=null;
        int filaElegida = this.jtDetalleSuministro.getSelectedRow();
        if (filaElegida < 0) {
          Utiles_MensajesDialogo.mensajeError("Debe elegir una licitacion!");
          this.jtDetalleSuministro.requestFocus();
        }
        else{
            LicitacionTO licTO= new LicitacionTO();
            codigo = this.jtDetalleSuministro.getValueAt(filaElegida, 0).toString().trim();
            descripcion= this.jtDetalleSuministro.getValueAt(filaElegida, 1).toString().trim();
            prove= jtDetalleSuministro.getValueAt(filaElegida, 3).toString().trim();
            fechaIni= this.jtDetalleSuministro.getValueAt(filaElegida, 4).toString().trim();
            fechaFin= this.jtDetalleSuministro.getValueAt(filaElegida, 5).toString().trim();
            monto= this.jtDetalleSuministro.getValueAt(filaElegida, 6).toString().trim();

            try {
                if(this.jckbActivas.isSelected()){
                     licTO  = GestionPedidosDelegate.getInstance().getDatosLicitacionCodigo(codigo,true,empresas.get(this.jcbEmpresa.getSelectedIndex()).getCodigo()).get(0);
                }
                else{
                     licTO  = GestionPedidosDelegate.getInstance().getDatosLicitacionCodigo(codigo,false,empresas.get(this.jcbEmpresa.getSelectedIndex()).getCodigo()).get(0);
                }
               
            } catch (Exception ex) {
                Logger.getLogger(jifAdministracion.class.getName()).log(Level.SEVERE, null, ex);
            }
            jdAdministrarLicitacion dialog = new jdAdministrarLicitacion(this,null, padre,true,licTO, codigo, descripcion, prove, fechaIni, fechaFin, monto);
            dialog.setLocationRelativeTo(null);
            dialog.setPadreDetalleAlmacen(this);
            dialog.setVisible(true);

           
        }

    }//GEN-LAST:event_jbtDetallesActionPerformed

    private void jbtEliminarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbtEliminarActionPerformed
        try {
            if (this.jtDetalleSuministro.getSelectedRow() < 0) {
                Utiles_MensajesDialogo.mensajeError("Debe elegir una licitacion");
                return;
            }
            if (Utiles_MensajesDialogo.mensajeConfirmacion("Esta seguro de eliminar la licitacion?"))
                GestionPedidosDelegate.getInstance().eliminarLicitacion(this.jtDetalleSuministro.getValueAt(jtDetalleSuministro.getSelectedRow(), 0).toString());
                this.consultar();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }//GEN-LAST:event_jbtEliminarActionPerformed

    private void jtfCodigoKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jtfCodigoKeyPressed
        this.jcbAno.setSelectedIndex(-1);
        if(KeyEvent.VK_ENTER == evt.getKeyCode() ){
           this.jtfDescipcionLic.requestFocus();
        }
    }//GEN-LAST:event_jtfCodigoKeyPressed

    private void jbtBuscarFocusGained(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_jbtBuscarFocusGained

    }//GEN-LAST:event_jbtBuscarFocusGained

    private void jbtBuscarKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jbtBuscarKeyPressed
         if (evt.getKeyCode() == KeyEvent.VK_ENTER ){
            this.jbtBuscar.doClick();
        }
    }//GEN-LAST:event_jbtBuscarKeyPressed

    private void jcbAnoKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jcbAnoKeyPressed
         if (evt.getKeyCode() == KeyEvent.VK_ENTER ){
            this.jbtBuscar.requestFocus();
        }
    }//GEN-LAST:event_jcbAnoKeyPressed

    private void jbBajaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbBajaActionPerformed
    try {
            if (this.jtDetalleSuministro.getSelectedRow() < 0) {
                Utiles_MensajesDialogo.mensajeError("Debe elegir una licitacion");
                return;
            }
            String codigo= this.jtDetalleSuministro.getValueAt(jtDetalleSuministro.getSelectedRow(), 0).toString();
            jdDarBaja dialog = new jdDarBaja(this, padre,true, codigo);
            dialog.setLocationRelativeTo(null);
            dialog.setPadreDetalleAlmacen(this);
            dialog.setVisible(true);

          
        } catch (Exception e) {
            e.printStackTrace();
        }
    }//GEN-LAST:event_jbBajaActionPerformed

    private void jckbActivasActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jckbActivasActionPerformed
        if(this.jckbActivas.isSelected()){
            this.jbtDetalles.setEnabled(true);
            this.jbtEliminar.setEnabled(true);
            this.jbBaja.setEnabled(true);
            try {
                List<TransferenciaTO> codigos = GestionPedidosDelegate.getInstance().obtenerCodigos(5);
                this.intelliHintsCodigos.setCompletionList(codigos);
            } catch (Exception ex) {
                Logger.getLogger(jifAdministracion.class.getName()).log(Level.SEVERE, null, ex);
            }

        }
        else{
            this.jbtDetalles.setEnabled(false);
            this.jbtEliminar.setEnabled(false);
            this.jbBaja.setEnabled(false);
            try {
                List<TransferenciaTO> codigos = GestionPedidosDelegate.getInstance().obtenerCodigos(6);
                 this.intelliHintsCodigos.setCompletionList(codigos);
            } catch (Exception ex) {
                Logger.getLogger(jifAdministracion.class.getName()).log(Level.SEVERE, null, ex);
            }
        }

    }//GEN-LAST:event_jckbActivasActionPerformed

    private void jbtImprimirActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbtImprimirActionPerformed

        MiTablePrint pp = new MiTablePrint(this.jtDetalleSuministro, "LICITACIONES", "LISTADO DE LICITACIONES");
        pp.showPrintPreview();
}//GEN-LAST:event_jbtImprimirActionPerformed

    private void jbtImprimirKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jbtImprimirKeyPressed
        if (evt.getKeyCode() == KeyEvent.VK_ENTER ){
            this.jbtImprimir.doClick();
        }
}//GEN-LAST:event_jbtImprimirKeyPressed

    private void jcbEmpresaKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jcbEmpresaKeyPressed
        if (evt.getKeyCode() == KeyEvent.VK_ENTER ){
            if(this.jcbEmpresa.getSelectedIndex()>=0){
                this.jtfCodigo.requestFocus();
            }
        }
    }//GEN-LAST:event_jcbEmpresaKeyPressed

    private void jtfDescipcionLicActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jtfDescipcionLicActionPerformed
       buscarDescripcionLicitacion();
    }//GEN-LAST:event_jtfDescipcionLicActionPerformed

    private void jtfDescipcionLicKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jtfDescipcionLicKeyPressed
        this.jcbAno.setSelectedIndex(-1);
        if (this.jtfCodigo.getText().trim().length() > 0)
            this.jtfCodigo.setText("");
    }//GEN-LAST:event_jtfDescipcionLicKeyPressed

    private void jCheckBox1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jCheckBox1ActionPerformed
        if(this.jCheckBox1.isSelected()){
            this.jcbEmpresa.setEnabled(true);
        } else{
            this.jcbEmpresa.setEnabled(false);
        }
        this.llenarComboEmpresa();

}//GEN-LAST:event_jCheckBox1ActionPerformed


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private administracion.BeanBinding.CboBeanBindingAno cboBeanBindingAno1;
    private administracion.BeanBinding.CboBeanBindingEmpresa cboBeanBindingEmpresa1;
    private javax.swing.JCheckBox jCheckBox1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JButton jbBaja;
    private javax.swing.JButton jbtBuscar;
    private javax.swing.JButton jbtCancelar;
    private javax.swing.JButton jbtDetalles;
    private javax.swing.JButton jbtEliminar;
    private javax.swing.JButton jbtImprimir;
    private javax.swing.JComboBox jcbAno;
    private javax.swing.JComboBox jcbEmpresa;
    private javax.swing.JCheckBox jckbActivas;
    private javax.swing.JLabel jlabelLicitacion;
    private javax.swing.JTable jtDetalleSuministro;
    private javax.swing.JTextField jtfCodigo;
    private javax.swing.JTextField jtfDescipcionLic;
    private javax.swing.JTextField jtfDescripcion;
    private javax.swing.JTextField jtfRuc;
    private org.jdesktop.beansbinding.BindingGroup bindingGroup;
    // End of variables declaration//GEN-END:variables

}
